package cn.lbl.face.leetCode;

/**
 * Created by 李柏霖
 * 2020/11/26 19:58
 */
/*
1.     1
2.     11
3.     21
4.     1211
5.     111221
6.     312211
 */
public class 外观数列 {
    public static void main(String[] args) {
        System.out.println(countAndSay(6));
    }

    //递归
    public static String countAndSay(int n) {
        String s="1";
        String result = "";
        int count=1;
        if (n == 1) {
            return s;
        }
        if (n > 2) {
            s= countAndSay(n-1);
        }
        for (int i = 0; i < s.length(); i++) {
            if (i+1<s.length() && s.charAt(i) == s.charAt(i+1)) {
                count++;
            }else {
                result+=String.valueOf(count)+s.charAt(i);
                count=1;
            }
        }
        return result;
    }
}
